package com.cx.controller;

import com.cx.common.ApiReturn;
import com.cx.pojo.Chassis;
import com.cx.service.ChassisService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("chassis")
@CrossOrigin//跨域
public class ChassisController {

    @Autowired
    ChassisService chassisService;

    //添加底盘转向
    @RequestMapping("insertChassis")
    @ResponseBody
    public ApiReturn insertChassis(Chassis chassis){
        int rows = chassisService.insert(chassis);
        if (rows<1){
            return ApiReturn.error("添加失败");
        }
        return  ApiReturn.success("添加成功");
    }

    //修改底盘转向
    @RequestMapping("updateChassis")
    @ResponseBody
    public ApiReturn updateChassis(Chassis chassis){
        int rows = chassisService.updateByPrimaryKey(chassis);
        if (rows<1){
            return ApiReturn.error("修改失败");
        }
        return ApiReturn.success("修改成功");
    }

    //删除底盘转向
    @RequestMapping("deleteChassis")
    @ResponseBody
    public ApiReturn deleteChassis(Integer chassisId) {
        int rows = chassisService.deleteByPrimaryKey(chassisId);
        if (rows < 1) {
            return ApiReturn.error("删除失败");
        }
        return ApiReturn.success("删除成功");
    }

    //根据id查询底盘转向
    @RequestMapping("selectChassisById")
    @ResponseBody
    public ApiReturn selectChassisById(Integer chassisId) {
        Chassis chassisInfo = chassisService.selectByPrimaryKey(chassisId);
        if (chassisInfo != null) {
            return ApiReturn.success("底盘转向数据详情",chassisInfo);
        }
        return ApiReturn.error("未获取该底盘转向数据详情");
    }

    //查询所有底盘转向
    @RequestMapping("selectAllChassis")
    @ResponseBody
    public ApiReturn selectAllChassis(Chassis chassis) {
        PageInfo<Chassis> page = chassisService.selectAllChassis(chassis);
        if (page.getList() != null) {
            return ApiReturn.success("所有底盘转向数据",page);
        }
        return ApiReturn.error("无数据");
    }
}
